﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace LunarSF.SHomeWorkshop.LunarMarkdownEditor.Widgets.MindMap
{
    /// <summary>
    /// Converts System.Drawing.Icon to System.Windows.Media.ImageSource
    /// </summary>
    public static class IconToImageSourceConverter
    {
        /// <summary>
        /// Converts System.Drawing.Icon to System.Windows.Media.ImageSource.
        /// </summary>
        /// <param name="icon">The icon.</param>
        /// <returns></returns>
        public static ImageSource Convert(Icon icon)
        {
            //Arguments checking
            if (icon == null)
                throw new ArgumentNullException("icon", "The icon can not be null.");

            ImageSource imageSource = Imaging.CreateBitmapSourceFromHIcon(
                icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            return imageSource;
        }
    }
}
